package com.example.mqltest.service.serviceImp;


import com.example.mqltest.dao.CourseDao;
import com.example.mqltest.dao.StudentDao;
import com.example.mqltest.dao.TeacherDao;
import com.example.mqltest.entity.Result;
import com.example.mqltest.entity.Student;
import com.example.mqltest.entity.Teacher;
import com.example.mqltest.service.AccountService;
import com.example.mqltest.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImp implements AccountService {
    @Autowired
    StudentDao studentDao;
    @Autowired
    TeacherDao teacherDao;
    @Autowired
    CourseDao courseDao;



    public MD5Utils md5Utils;

    @Override
    public Result login(String userId, String password) {
        try {
            Student student=studentDao.Login( userId,password );
            if(student!=null){
                student.setRole( "student" );
                return new Result(200,"登陆成功",student);
            }
            Teacher teacher=teacherDao.Login( userId,password );
            if(teacher!=null){
                teacher.setRole( "teacher" );
                return new Result(200,"登陆成功",teacher);
            }
            return new Result(404,"账号或密码错误","");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(400,"网络繁忙，稍后再试","");
        }

    }
}
